<template>
	<view class="content">
		<view class="searchBox"  @click="toSearch()">
			<van-search
			  :value=searchValue
			  shape="round"
			  background="#fff"
			  placeholder="请输入搜索关键词"
			  disabled
			/>
		</view>
		<view class="banner">
			<image  class="introImg" @click="toLg(showList[1])" :src="showList[0].introUrl+'?imageView2/2/w/750/q/85'" mode=""></image>
		</view>
		<view class="intro bt">
			<view @click="toSort(item.id)" class="link" v-for="(item,index) in link" :key="index">
				<text>{{item.styleName}}</text>
			</view>
		</view>
		<view class="lg bt">
			<view class="head">
				<text>家居灵感</text>
				<view class="right" v-if="svip.id!=0" @click="toSort(svip.id)">
					<text>{{svip.styleName}}</text>
					<van-icon name="arrow" color="#faa819" size="22px"/>
				</view>
			</view>
			<view class="lBox" @click="toLg(showList[1])">
				<!-- <image src="https://yueyuan-1319780509.cos.ap-chengdu.myqcloud.com/2.png" mode=""></image> -->
				<image :src="showList[1].introUrl+'?imageView2/2/w/330/h/434/q/85'" mode=""></image>
			</view>
			<view class="rBox">
				<image @click="toLg(showList[2])" :src="showList[2].introUrl+'?imageView2/2/w/330/h/202/q/85'" mode=""></image>
				<image @click="toLg(showList[3])" :src="showList[3].introUrl+'?imageView2/2/w/330/h/202/q/85'" mode=""></image>
				<!-- <image @click="toLg()" src="https://yueyuan-1319780509.cos.ap-chengdu.myqcloud.com/3.png" mode=""></image>
				<image @click="toLg()" src="https://yueyuan-1319780509.cos.ap-chengdu.myqcloud.com/4.png" mode=""> -->
			</view>
		</view>
		<view class="lg">
			<view class="head">
				新品推荐
			</view>
			<view class="tj" v-for="(item,index) in goodsList" :key="item.id">
				<image @click="to(item)" :src="item.mainImageUrl+'?imageView2/1/w/240/h/240/q/85'" mode=""></image>	
				<view class="info"  @click="to(item)">
					<view class="name">{{item.name}}</view>
					<view class="sku">{{item.size}}</view>
					<view class="material">{{item.material}}</view>
					<view class="price">
						<view class="lefts">
							¥ <text class="zs">{{item.factoryPrice}}</text>
							<text class="ws">.00</text>
						</view>
						<view class="rights">
							<van-icon name="fire" size="18" color="#FFC100"/>
							<text>{{item.saleNum || '0'}}</text>
						</view>
					</view>
					<view class="num">
						<view class="left">
							
							<!-- <view class="ys">
								已售<text>{{80-index*9+5}}</text>件
							</view>
							<view class="barBox">
								<view class="bar" :style="{'width':(230-index*10+6)+'rpx'}">
								</view>
							</view> -->
						</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '未来屋图文介绍',
				goodsList:[],
				phone:'11111111111',
				// link:['德国当代','VERSACE','美克·美家','卡德维','TFG','MEIJ','宜家','居好家'],
				link:[],
				collect:0,
				goodsList:[],
				banner: "https://yueyuan-1319780509.cos.ap-chengdu.myqcloud.com/1.png",
				videoList:[],
				videoStatus:false,
				showList:[],
				isAuth:0,
				createBy:0,
				svip:{
					styleName:'',
					id:0
				}
			}
		},
		onLoad(query) {
			this.getGoodsList();
			this.getRecommendInfoList();
			this.getAuth();
		},
		onShareAppMessage(){
		},
		methods: {
			//查询授权
			getAuth(){
				let phone = uni.getStorageSync('phone')
				if(phone){
					const requestParam = {
						url: "/app/mall/getUserByPhone",
						method: "GET",
						data:{
							phone:phone,
						},
						callBack: (res) => {
							this.isAuth=res.data.isAuth;
							this.createBy=res.data.createBy;
							this.getStyle();
						}
					}
					this.$request(requestParam);
				}else{
					this.getStyle();
				}
				
			},
			//家居灵感
			getRecommendInfoList(){
				const requestParam = {
					url: "/app/mall/getRecommendInfoList",
					method: "GET",
					callBack: (res) => {
						console.log(res);
						this.showList=res.rows;
						// this.merchantsData=res.data;
						// if(this.merchantsData.videoUrl){
						// 	this.videoList=this.merchantsData.videoUrl.split(",");
						// }
					}
				}
				this.$request(requestParam);
			},
			//推荐商品
			getGoodsList(){
				const requestParam = {
					url: "/app/mall/commodityList",
					method: "GET",
					data:{
						pageNum: 1,
						pageSize: 10,
					},
					callBack: (res) => {
						this.goodsList=res.rows;
					}
				}
				this.$request(requestParam);
			},
			to(item){
				uni.navigateTo({
					url: '/pages/detail/index?id='+item.id
				});
			},
			toLg(item){
				console.log(item,888)
				if(item.commodityId){
					uni.navigateTo({
						url: '/pages/detail/lg?info='+JSON.stringify(item)
					});	
				}
			},
			//-----------------------------------
			toSort(id){
				uni.navigateTo({
					url: '/pages/shoping/index?id='+id
				});
			},
			toSearch(){
				uni.navigateTo({
					url: '/pages/list/index'
				});
			},
			collection(commodityId){
				if(uni.getStorageSync('userId')){
					const requestParam = {
						url: "/app/mall/addUserCommodity",
						method: "POST",
						data:{
							commodityId: commodityId,
							userId: uni.getStorageSync('userId'),
						},
						callBack: (res) => {
							console.log(res,999)
						}
					}
					this.$request(requestParam);
				}else{
					uni.navigateTo({
						url: '/pages/me/user'
					});
				}
			},
			showPopups(url) {
				wx.previewMedia({
					sources:[{
						url:url,
						type: 'image'
					}]
				})
			},
			getStyle(){
				const requestParam = {
					url: "/app/mall/styleList",
					method: "GET",
					data:{
						pageNum: 1,
						pageSize:20,
						styleLevel:1,
						parentId:0,
					},
					callBack: (res) => {
						if(this.isAuth==1){
							this.link=res.rows.filter(value =>value.isSvip != 1);
						}else{
							this.link=res.rows.filter(value => value.isVip != 1 && value.isSvip != 1);
						}
						if(this.createBy==1){
							this.svip=res.rows.filter(value => value.isSvip == 1)[0];	
						}
					}
				}
				this.$request(requestParam);
			},
		}
	}
</script>

<style lang="scss">
	@import './style.scss';
</style>
